/**********************************************************************************
Program:       chinaweathergadget

License:       GNU/GPL version 3

File:          Form_About.cs

Description:   “关于”窗体

Author:        Guangyu Liu （lgy0417@gmail.com）

Environment:   .NET Framework v2.0 or later version

Usage/Example: README_chs.txt

Last Modified: 2010.08.30

***********************************************************************************/


using System;
using System.Drawing;
using System.Resources;
using System.Reflection;
using System.Windows.Forms;
using PrettifiedControls.PrettifiedButton;


namespace GUI
{
	public class AboutForm : Form
	{
		#region
		
		private ResourceManager rm;
		private PictureBox picbox;
		private Label buildTimeLabel;
		private Label appNameLabel;
		private static readonly string appNameString = "中国城市天气信息小工具 v6.0";
		private Label authorLabel;
		private LinkLabel authorNameLabel;
		private static readonly string authorEmail = @"lgy0417@gmail.com";
		private Label homePageLabel;
		private LinkLabel homePageAddrLabel;
		private static readonly string homePageURL = @"http://code.google.com/p/chinaweathergadget/";
		private GroupBox gBox;
		private TextBox tBox;
		private ButtonNew ok;
		private static readonly string gplString = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version."
												 + Environment.NewLine
												 + Environment.NewLine
												 + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details."
												 + Environment.NewLine
												 + Environment.NewLine
												 + "You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.";

		#endregion
	
		public AboutForm()
		{
			InitializeComponents();
		}
		
		public void InitializeComponents()
		{
			rm = new ResourceManager("ChinaWeatherGadget", Assembly.GetExecutingAssembly());

			#region PictureBox
			picbox = new PictureBox();
			picbox.Location = new Point(25, 25);
			picbox.Size = new Size(40, 40);
			picbox.SizeMode = PictureBoxSizeMode.StretchImage;
			picbox.Image = (Image)rm.GetObject("48x48");
			picbox.TabStop = false;
			this.Controls.Add(picbox);
			#endregion
			
			#region Label & LinkLabel
			
			buildTimeLabel = new Label();
			buildTimeLabel.AutoSize = true;
			buildTimeLabel.Top = 5;
			buildTimeLabel.Font = new Font("Times New Roman", 9);
			buildTimeLabel.ForeColor = Color.Gray;
			buildTimeLabel.Text = "Build Time : " + rm.GetString("BuildTime");
			this.Controls.Add(buildTimeLabel);
			
			appNameLabel = new Label();
			appNameLabel.AutoSize = true;
			appNameLabel.Left = picbox.Right + 15;
			appNameLabel.Top = picbox.Location.Y + picbox.Size.Height / 2;
			appNameLabel.Text = appNameString;
			this.Controls.Add(appNameLabel);
			
			authorLabel = new Label();
			authorLabel.AutoSize = true;
			authorLabel.Left = picbox.Left;
			authorLabel.Top = picbox.Bottom + 15;
			authorLabel.Text = "作者：";
			this.Controls.Add(authorLabel);
			
			authorNameLabel = new LinkLabel();
			authorNameLabel.AutoSize = true;
			authorNameLabel.Left = authorLabel.Left + 70;
			authorNameLabel.Top = authorLabel.Top - 2;
			authorNameLabel.Font = new Font("Times New Roman", 10);
			authorNameLabel.Text = "Guangyu Liu  ( " + authorEmail + " )";
			authorNameLabel.TabStop = true;
			authorNameLabel.TabIndex = 10;
			authorNameLabel.LinkArea = new LinkArea(authorNameLabel.Text.IndexOf('(') + 2, authorEmail.Length);
			this.Controls.Add(authorNameLabel);
			authorNameLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(this.authorEmail_LinkClicked);
			
			homePageLabel = new Label();
			homePageLabel.AutoSize = true;
			homePageLabel.Left = authorLabel.Left;
			homePageLabel.Top = authorLabel.Bottom + 15;
			homePageLabel.Text = "项目主页：";
			this.Controls.Add(homePageLabel);
			
			homePageAddrLabel = new LinkLabel();
			homePageAddrLabel.AutoSize = true;
			homePageAddrLabel.Left = authorNameLabel.Left;
			homePageAddrLabel.Top = homePageLabel.Top - 2;
			homePageAddrLabel.Font = authorNameLabel.Font;
			homePageAddrLabel.Text = homePageURL;
			homePageAddrLabel.TabStop = true;
			homePageAddrLabel.TabIndex = 20;
			homePageAddrLabel.LinkArea = new LinkArea(0, homePageURL.Length);
			this.Controls.Add(homePageAddrLabel);
			homePageAddrLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(this.HomePage_LinkClicked);
			
			#endregion
			
			#region GroupBox
			gBox = new GroupBox();
			gBox.Left = picbox.Location.X;
			gBox.Top = homePageLabel.Bottom + 20;
			gBox.Font = new Font("Calibri", 9);
			gBox.Text = "GNU General Public Licence";
			gBox.FlatStyle = FlatStyle.System;
			this.Controls.Add(gBox);
			#endregion
			
			#region TextBox
			tBox = new TextBox();
			tBox.BorderStyle = BorderStyle.None;
			tBox.ScrollBars = ScrollBars.Vertical;
			tBox.BackColor = Color.FromArgb(229,239,252);
			tBox.Multiline = true;
			tBox.WordWrap = true;
			tBox.ReadOnly  = true;
			tBox.AcceptsReturn = true;
			tBox.Text = gplString;
			tBox.Location = new Point(20, 30);
			tBox.ClientSize = new Size(300, 150);
			gBox.ClientSize = new Size(tBox.ClientSize.Width + 2 * tBox.Left, tBox.ClientSize.Height + tBox.Top + 20);
			gBox.Controls.Add(tBox);
			#endregion
		
			#region button
			ok = new ButtonNew();
			ok.Height = 20;
			ok.Width = 60;
			ok.Top = gBox.Bottom + 20;
			ok.Left = gBox.Left + gBox.Width / 2 - ok.Width / 2;
			ok.Text = "确定";
			ok.Image = (Image)rm.GetObject("ok_png");
			ok.ImageWidth = 14;
			ok.TextImageRelation = TextImageRelation.ImageBeforeText;
			ok.TabIndex = 0;
			this.Controls.Add(ok);
			ok.Click += new System.EventHandler(this.buttonOK_Click);
			#endregion
			
			#region form
			this.StartPosition = FormStartPosition.CenterScreen;
			this.FormBorderStyle = FormBorderStyle.None;
			this.BackColor = tBox.BackColor;
			this.AcceptButton = ok;
			this.ClientSize = new Size(2 * gBox.Left + gBox.Width, ok.Bottom + 15);
			this.ShowInTaskbar = false;
			this.TopMost = true;
			buildTimeLabel.Left = this.ClientSize.Width - 3 - buildTimeLabel.PreferredWidth;
			#endregion
		}
		
		private void buttonOK_Click(object Sender, EventArgs e)
		{
			this.Close();
		}
		
		private void authorEmail_LinkClicked(object Sender, LinkLabelLinkClickedEventArgs e)
		{
			System.Diagnostics.Process.Start("mailto:" + authorEmail);
			e.Link.Visited = true;
		}
		
		private void HomePage_LinkClicked(object Sender, LinkLabelLinkClickedEventArgs e)
		{
			System.Diagnostics.Process.Start(homePageURL);
			e.Link.Visited = true;
		}
	}
}